package com.test02_程序基础应用;

import org.junit.Test;

/**
 * 实现任意两个整数的互换
 */
public class YootkDemo_01 {

    @Test
    public void test1() {
        int x = 10;
        int y = 20;
        System.out.println("【交换前】x = " + x + "、y = " + y);
        int temp = x;   // 引入第三方变量
        x = y;
        y = temp;
        System.out.println("【交换后】x = " + x + "、y = " + y);
    }

    @Test
    public void test2() {
        int x = 10;
        int y = 20;
        System.out.println("【交换前】x = " + x + "、y = " + y);
        x += y;
        y = x - y;
        x = x - y;
        System.out.println("【交换后】x = " + x + "、y = " + y);
    }
}
